package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.enums.ChatType;
import com.example.enums.DeleteFlag;
import com.example.mapper.SessionMapper;
import com.example.pojo.Session;
import com.example.service.SessionService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;


@Service
@AllArgsConstructor
public class SessionServiceImpl extends ServiceImpl<SessionMapper, Session> implements SessionService{

    private final SessionMapper sessionMapper;
    @Override
    public List<Session> getHistorySessionList(String type) {
        LambdaQueryWrapper<Session> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Session::getType, type);
        return sessionMapper.selectList(queryWrapper);
    }

    @Override
    public List<String> getHistorySessionIdList(String type) {
        List<Session> sessionList = getHistorySessionList(type);
        if (ObjectUtils.isNotEmpty(sessionList)) {
            return sessionList.stream().map(Session::getSessionId).toList();
        }
        return List.of();
    }

    @Override
    public Session addSession(Session session) {
        Session padingSession = new Session();
        padingSession.setSessionId(session.getSessionId());
        padingSession.setType(ChatType.CHAT.type);
        padingSession.setSessionName("新会话");
        padingSession.setUserId(UUID.randomUUID().toString());
        padingSession.setDeleteFlag(DeleteFlag.NOT_DELETE.status);
        padingSession.setCreateTime(LocalDateTime.now());
        sessionMapper.insert(padingSession);
        return null;
    }

    @Override
    public Session getSessionById(String sessionId) {
        return sessionMapper.selectById(sessionId);
    }
}




